import { defineStore } from "pinia"
import { ref } from "vue"

export enum IDENTITY_ENUMS {
  ADMIN = "teacher",
  PARENT = "parent",
  LOW = "low"
}
export interface LoginInfo {
  unionId: string
  openId: string
}

export interface TeacherInfo {
  subId: number
  subType: number
  subName: string
  picUrl: string
}

export interface ParentInfo {
  createTimeUx: number
  isDelete: number
  isSubscribe: number
  mobile: number
  openId: string
  parentId: number
  relation: string
  unionId: string
  updateTimeUx: number
  userId: string
}

export type UserInfo<T = any> = T extends "teacher" ? TeacherInfo : ParentInfo

export const useUserStore = defineStore(
  "user",
  () => {
    const token = ref("")
    const userInfo = ref<UserInfo>()
    const userType = ref<`${IDENTITY_ENUMS}`>(IDENTITY_ENUMS.ADMIN)
    const loginInfo = ref<LoginInfo>({
      unionId: "",
      openId: ""
    })

    return {
      token,
      userInfo,
      userType,
      loginInfo
    }
  },
  {
    persist: true
  }
)
